home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Util / conv / MIDI2asm.lha / MIDI2asm / fixmidi.rexx < prev    next >
OS/2 REXX Batch file  |  1999-08-22  |  1KB  |  34 lines

  1. /* fix midifile V1.1 */
  2. /* © by Stefan Haubenthal 1995/98
  3. Usage: fixmidi file_to_fix
  4.        look for "t:file_to_fix" */
  5. if ~arg() then say sourceline(3)
  6. if ~open(oldfile,arg(1)) then exit 0
  7. if ~open(newfile,"t:"arg(1),'W') then exit 10
  8. ok=1
  9. do track=0
  10.     magic=readch(oldfile,4)
  11.     if eof(oldfile) | magic~="MThd" & magic~="MTrk" then leave
  12.     len=c2d(readch(oldfile,4))
  13.     chunk=readch(oldfile,65535)
  14.     pos=pos("MTrk",chunk)-1
  15.     if pos=-1 then pos=length(chunk)
  16.     diff=pos-len
  17.     if diff~=0 then ok=0
  18.     if abs(diff)=1 then s=""
  19.                        else s="s"
  20.     select
  21.         when diff=0 then say "Track "track" is okay"
  22.         when diff<0 then say "Track "track" is "||-diff" byte"s" too short"
  23.         when diff>0 then say "Track "track" is "diff" byte"s" too long"
  24.     end
  25.     call seek(oldfile,-(length(chunk)-pos))
  26. /*    call writech(newfile,magic||d2c(pos,4)substr(chunk,1,pos))*/
  27.     call writech(newfile,magic||d2c(len,4)substr(chunk,1,len))
  28. end
  29. call close(newfile)
  30. address command
  31. if ok then delete "22"x"t:"arg(1)"22"x
  32.       else filenote "22"x||arg(1)"22"x "corrupt"
  33. if ~ok then exit 5
  34.